package com.qfedu.mesadmin.md.client.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qfedu.mes.common.PageParam;
import com.qfedu.mes.common.PageVO;
import com.qfedu.mes.entity.md.MdClient;
import com.qfedu.mes.entity.md.MdUnitMeasure;
import com.qfedu.mesadmin.md.client.dao.MdClientDao;
import com.qfedu.mesadmin.md.client.params.AddClientParam;
import com.qfedu.mesadmin.md.client.params.ClientPageParam;
import com.qfedu.mesadmin.md.client.service.MdClientService;
import com.qfedu.mesadmin.md.client.vo.ClientTypeVO;
import com.qfedu.mesadmin.md.client.vo.MdClientVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MdClientServiceImpl implements MdClientService {

    @Resource
    private MdClientDao mdClientDao;

    //分页数据
    @Override
    public PageVO<MdClientVO> selectInfo(PageParam param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<MdClientVO> mdClientVOS = mdClientDao.selectVO();

        Page pageInfo = (Page) mdClientVOS;
        PageVO<MdClientVO> pageVo = new PageVO<>(pageInfo.getTotal(), mdClientVOS);

        return pageVo;
    }

    //模糊查询分页数据
    @Override
    public PageVO<MdClientVO> searchInfo(ClientPageParam param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<MdClientVO> mdClientVOS = mdClientDao.selectByForm(param);

        Page pageInfo = (Page) mdClientVOS;
        PageVO<MdClientVO> pageVO = new PageVO<>(pageInfo.getTotal(), mdClientVOS);

        return pageVO;
    }

    //类型列表
    @Override
    public List<ClientTypeVO> selectType() {
        return mdClientDao.selectType();
    }

    //插入数据
    @Override
    public void insertClient(AddClientParam param) {
        MdClient mdClient = new MdClient();
        BeanUtils.copyProperties(param, mdClient);
        mdClientDao.insert(mdClient);
    }

    //删除
    @Override
    public void deleteById(Long id) {
        mdClientDao.deleteById(id);
    }

    //修改时展示数据
    @Override
    public AddClientParam selectById(Long id) {
        AddClientParam addClientParam = mdClientDao.selectById(id);
        return addClientParam;
    }

    //更新
    @Override
    public void updateById(AddClientParam param) {
        MdClient mdClient = new MdClient();
        BeanUtils.copyProperties(param, mdClient);
        mdClientDao.updateById(mdClient);

    }

    //总条数
    @Override
    public Integer selectTotal() {
        return mdClientDao.total();
    }
}
